package com.lancoo.ccas53.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.lancoo.ccas53.config.LancooConfig;
import com.lancoo.ccas53.entity.*;
import com.lancoo.ccas53.pojo.constant.GlobalConstant;
import com.lancoo.ccas53.pojo.response.BasicPlatformResponse;
import com.lancoo.ccas53.service.*;
import com.lancoo.ccas53.service.impl.StudentServiceImpl;
import com.lancoo.ccas53.util.ExcelPoiUtil;
import com.lancoo.ccas53.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
@Api(tags = "测试类")
@RestController
@RequestMapping("/test")
public class TestController {
    @Resource
    private TeacherService teacherService;
    @Resource
    private ScheduleService scheduleService;
    @Resource
    private StudentService studentService;
    @Resource
    private TeachingClassStudentService teachingClassStudentService;
    @Resource
    private TeachingClassService teachingClassService;
    @Value("${lancoo.schoolFlag}")
    private Integer schoolFlag;
    @Resource
    private CourseService courseService;
    @Resource
    private LancooConfig lancooConfig;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private StudentServiceImpl studentServiceImpl;
    @Resource
    private UserSettingService userSettingService;

    static Map<String, List<ColEntity>> heads = new HashMap<>();// 最终导出的多个sheet的表头
    static Map<String, List<Map<String, String>>> datas = new HashMap<>();// 最终导出的多个sheet的内容
    static Map<String, Integer> types = new HashMap<>();// 最终导出的每个sheet的样式类型
    static Map<String, List<Integer>> autoRowHeights = new HashMap<>();// 最终导出的每个sheet的需要自适应行高的行号
    static Map<String, List<Integer>> mergeIndexs = new HashMap<>();

//    @ApiOperation("本地--清理缓存")
//    @GetMapping(value = "/removeTest")
//    public void removeTest() {
//        userSettingService.lambdaUpdate().remove();
//        Integer inte = 1;
//    }


//    @ApiOperation("本地--清理缓存")
//    @GetMapping(value = "/clearCache")
//    public void clearCache() {
//        Integer taskId = 2000044;
//        String tempKey = "Online";
//        String key1 = GlobalConstant.REDIS_PREFIX + taskId + StrUtil.C_COLON + "StudentOptionalClass";
//        String key2 = GlobalConstant.REDIS_PREFIX + taskId + StrUtil.C_COLON + "TeachingClassStudent";
//        String key3 = GlobalConstant.REDIS_PREFIX + taskId + StrUtil.C_COLON + "TeachingClassDetail";
//        List<Long> studentIds = studentService.lambdaQuery().eq(Student::getTaskId, taskId).list()
//                .stream().map(Student::getStudentId).collect(Collectors.toList());
//        String[] keys = new String[studentIds.size()];
//        int i = 0;
//        for (Long studentId : studentIds) {
//            String key = key1 + StrUtil.C_COLON + studentId + StrUtil.C_COLON + tempKey;
//            keys[i] = key;
//            i += 1;
//        }
//        redisUtil.del(keys);
//        redisUtil.del(key2);
//        redisUtil.del(key3);
//    }

//    @ApiOperation("本地--清理预选课缓存")
//    @GetMapping(value = "/clearPreCache")
//    public void clearPreCache() {
//        Integer taskId = 2000044;
//        //预选课缓存数据删除
//        String redisKey = studentServiceImpl.getCacheKeys(taskId, null, 8, null);
//        String key1 = GlobalConstant.REDIS_PREFIX + taskId + StrUtil.C_COLON + "StudentOptionalCourse";
//        List<Long> studentIds = studentService.lambdaQuery().eq(Student::getTaskId, taskId).list()
//                .stream().map(Student::getStudentId).collect(Collectors.toList());
//        String[] keys = new String[studentIds.size()];
//        int i = 0;
//        for (Long studentId : studentIds) {
//            String key = key1 + StrUtil.C_COLON + studentId + StrUtil.C_COLON + "Primary";
//            keys[i] = key;
//            i += 1;
//        }
//        redisUtil.del(redisKey);
//        redisUtil.del(keys);
//    }

//    @ApiOperation("本地--东华修改考核方式")
//    @GetMapping(value = "/updateAssessment")
//    public String updateClassName() {
//        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getTaskId, 1000053).list();
//        List<Long> courseIds = teachingClassList.stream().map(TeachingClass::getCourseId).distinct().collect(Collectors.toList());
//        List<Course> courseList = courseService.lambdaQuery().in(Course::getCourseId, courseIds).list();
//        List<String> baseCourseIds = courseList.stream().map(Course::getBaseCourseId).distinct().collect(Collectors.toList());
//        for (TeachingClass teachingClass : teachingClassList) {
//            if (teachingClass.getAssessmentId().equals(1000060L)) {
//                teachingClass.setAssessmentId(20L);
//                teachingClass.setAssessmentName("考查");
//            } else if (teachingClass.getAssessmentId().equals(1000059L)) {
//                teachingClass.setAssessmentId(12L);
//                teachingClass.setAssessmentName("笔试（闭卷）");
//            }
//            if (teachingClass.getAssessmentId().equals(12L)){
//                teachingClass.setAssessmentName("考试");
//            }
//        }
//        teachingClassService.updateBatchById(teachingClassList);
//
//        StringBuilder error = new StringBuilder();
//        for (Course course : courseList) {
//            TeachingClass teachingClass = teachingClassList.stream().filter(a -> a.getCourseId().equals(course.getCourseId())).findFirst().get();
//
//            String path = "/BaseApi/UserMgr/TeachInfoMgr/setTermCourseExamInfo";
//            Map<String, String> map = new HashMap<>();
//            String strAppId = lancooConfig.getSysId();
//            String Md5_AppId = DigestUtils.md5DigestAsHex(strAppId.getBytes());
//            StringBuilder sb = new StringBuilder(Md5_AppId);
//            String strAccess_token = sb.reverse().toString();
//
//            map.put("appid", strAppId);
//            map.put("access_token", strAccess_token);
//            map.put("schoolId", "S-14362");
//            map.put("term", "2024-202501");
//            map.put("courseNo", course.getBaseCourseId());
//            map.put("testType", teachingClass.getAssessmentId().toString());
//            String url = lancooConfig.getBaseAddr().concat(path);
//            String body = JSON.toJSONString(map);
//            HttpRequest post = HttpUtil.createPost(url).body(body);
//            HttpResponse execute = post.execute();
//            BasicPlatformResponse basicPlatformResponse = JSONObject.parseObject(execute.body(), BasicPlatformResponse.class);
//            if (!basicPlatformResponse.getStatusCode().equals(200)) {
//                error.append(course.getCourseId());
//            }
//        }
//        return error.toString();
//
//    }

//    @ApiOperation("本地--东华修改教学班名称")
//    @GetMapping(value = "/updateClassName")
//    public ResponseObject<String> updateClassName() {
//        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getTaskId, 1000053).list();
//        for (TeachingClass teachingClass : teachingClassList) {
//            if (teachingClass.getIsOptional().equals(1)) {
//                String newName = teachingClass.getTeachingClassName() + "-" + teachingClass.getGradeName();
//                teachingClass.setTeachingClassName(newName);
//            }else {
//                String newName = teachingClass.getTeachingClassName() + "-" + teachingClass.getCourseName();
//                teachingClass.setTeachingClassName(newName);
//            }
//        }
//        teachingClassService.updateBatchById(teachingClassList);
//        return null;
//    }

//    @GetMapping("/ttt")
//    public void ttt(@RequestParam Integer taskId) {
//        teachingClassService.allTeachingClassToExcel(taskId, "");
//        scheduleService.allScheduleToExcel(taskId, null);
//    }

    @ApiOperation("测试动态设置表头导出")
    @GetMapping(value = "/test")
    public void exportScheduleTest(HttpServletResponse response) throws Exception {

//        ExportParams params = new ExportParams();
//        //生成要导出的数据
//        List<Map<String, Object>> resultList = new ArrayList<>();
//        List<List<Object>> tempDataList = new ArrayList<>();
//        List<Object> tempRowList1 = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
//        tempDataList.add(tempRowList1);
//        List<Object> tempRowList2 = new ArrayList<>(Arrays.asList(0, 1, 8, 3, 4, 5, 7, 7, 8, 9, 10));
//        tempDataList.add(tempRowList2);
//        List<Object> tempRowList3 = new ArrayList<>(Arrays.asList(1, 1, 2, 8, 4, 5, 6, 7, 8, 8, 10));
//        tempDataList.add(tempRowList3);
//        for (List<Object> rowList : tempDataList) {
//            Map<String, Object> rowMap = new HashMap<>();
//            for (int i = 1; i <= rowList.size(); i++) {
//                rowMap.put("title" + i, rowList.get(i - 1));
//            }
//            resultList.add(rowMap);
//        }
//        //列名
//        List<ExcelExportEntity> entityList = new ArrayList<>();
//        for (int i = 1; i <= tempRowList1.size(); i++) {
//            ExcelExportEntity entity = new ExcelExportEntity("标题" + i, "title" + i);
//            entityList.add(entity);
//        }
//        Workbook workbook = ExcelExportUtil.exportExcel(params, entityList, resultList);
//
//        response.addHeader("Content-Disposition", "filename=test.xlsx");
//        //设置类型，扩展名为.xls
//        response.setContentType("application/vnd.ms-excel");
//        workbook.write(response.getOutputStream());


//        List<ExcelTest> excelPreSelectCourseLogs = new ArrayList<>();
//
//        List<Student> studentList = studentService.lambdaQuery().eq(Student::getTaskId, 1000053).eq(Student::getGradeId,"ae9cb18cb59a81f6e93d125820d32782").eq(Student::getCollegeName, "智能机电学院").list();
//
//        studentList.forEach(o -> {
//            ExcelTest excelPreSelectCourseLog = new ExcelTest();
//
//            excelPreSelectCourseLog.setBaseStudentId(o.getBaseStudentId());
//
//            excelPreSelectCourseLogs.add(excelPreSelectCourseLog);
//
//        });
//
//
//
//
//
//        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
//
//        response.setCharacterEncoding("UTF-8");
//        response.setHeader("content-Type", "application/vnd.ms-excel; charset=utf-8");
//
//        MyExcelUtils.exportExcel(excelPreSelectCourseLogs,
//                "",
//                "选课日志导出",
//                ExcelTest.class,
//                "选课日志导出" + time + ".xls", response);


//        List<Student> students = studentService.lambdaQuery().eq(Student::getTaskId, 1000053).eq(Student::getClassName, "23级机电一体化技术2班").list();
//
//        List<TeachingClassStudent> teachingClassStudents  =new ArrayList<>();
//
//
//        students.forEach(o->{
//            TeachingClassStudent teachingClassStudent = new TeachingClassStudent();
//            teachingClassStudent.setTeachingClassId(1690L);
//            teachingClassStudent.setStudentId(o.getStudentId());
//            teachingClassStudent.setCourseId(2003583L);
//            teachingClassStudent.setFlag(1);
//            teachingClassStudents.add(teachingClassStudent);
//        });
//
//        teachingClassService.lambdaUpdate().eq(TeachingClass::getTeachingClassId,1690L).set(TeachingClass::getClassNum,students.size()).update();
//
//        teachingClassStudentService.lambdaUpdate().eq(TeachingClassStudent::getTeachingClassId,1690L).remove();
//        teachingClassStudentService.saveOrUpdateBatch(teachingClassStudents);


        // exportList为表头总的集合，导出的EXCEL表格的表头完全是按照这个来生成的
//        List<ExcelExportEntity> exportList = new ArrayList<>();
//        // 创建最底部的一级表头10个
//        ExcelExportEntity A1 = new ExcelExportEntity("一级表头A1", "a1");
//        ExcelExportEntity A2 = new ExcelExportEntity("一级表头A2", "a2");
//        ExcelExportEntity B1 = new ExcelExportEntity("一级表头B1", "b1");
//        ExcelExportEntity B2 = new ExcelExportEntity("一级表头B2", "b2");
//        ExcelExportEntity B3 = new ExcelExportEntity("一级表头B3", "b3");
//        ExcelExportEntity C1 = new ExcelExportEntity("一级表头C1", "c1");
//        ExcelExportEntity C2 = new ExcelExportEntity("一级表头C2", "c2");
//        ExcelExportEntity D1 = new ExcelExportEntity("一级表头D1", "d1");
//        ExcelExportEntity D2 = new ExcelExportEntity("一级表头D2", "d2");
//        ExcelExportEntity D3 = new ExcelExportEntity("一级表头D3", "d3");
//
//        // 创建二级表头，并将二级表头对应的下级一级表头放入其中，以此类推...
//        ExcelExportEntity A = new ExcelExportEntity("二级表头A", "a");
//        A.setList(Arrays.asList(A1, A2));
//        ExcelExportEntity B = new ExcelExportEntity("二级表头B", "b");
//        B.setList(Arrays.asList(B1, B2, B3));
//        ExcelExportEntity C = new ExcelExportEntity("二级表头C", "c");
//        C.setList(Arrays.asList(C1, C2));
//        ExcelExportEntity D = new ExcelExportEntity("二级表头D", "d");
//        D.setList(Arrays.asList(D1, D2, D3));
//
//        ExcelExportEntity AA = new ExcelExportEntity("三级表头AA", "aa");
//        AA.setList(Arrays.asList(A, B, C));
//        ExcelExportEntity AB = new ExcelExportEntity("三级表头BB", "bb");
//        AB.setList(Arrays.asList(D));
//
//        ExcelExportEntity XYZ = new ExcelExportEntity("四级表头", "xyz");
//        XYZ.setList(Arrays.asList(AA, AB));
//
//        // 最后表头设置完毕，将总和起来的四级表头放入
//        exportList.add(XYZ);
//        ExportParams params = new ExportParams("表格标题__布拉布拉布拉", "随便取个sheet名", ExcelType.XSSF);
//
//        List<Map<String, Object>> resultList = new ArrayList<>();
//        Workbook workbook = ExcelExportUtil.exportExcel(params, exportList, resultList);
//
//        response.addHeader("Content-Disposition", "filename=test.xlsx");
//        //设置类型，扩展名为.xls
//        response.setContentType("application/vnd.ms-excel");
//        workbook.write(response.getOutputStream());


    }


    @ApiOperation("测试动态设置表头导出")
    @GetMapping(value = "/test2")
    public void exportScheduleTest2(HttpServletResponse response) throws Exception {


        多级表头Map();
//        多级表头Obj();
//        多级表头Obj1();
//        多级表头Obj2();
//        纵向合并单元格();
        // 多个sheet导出
        ExcelPoiUtil excelTool = new ExcelPoiUtil("教学班数据导出");
        //HSSFWorkbook workbook = excelTool.exportWorkbook(heads, datas, 0, null, null); // 这里多个sheet都用的同一个样式
        HSSFWorkbook workbook = excelTool.exportWorkbook(heads, datas, types, null, mergeIndexs);
        excelTool.save(workbook, "D:\\test.xls");

    }

    public static void 纵向合并单元格() throws Exception {
        List<Map<String, String>> titleList = new ArrayList<>();
        Map<String, String> titleMap = new HashMap<String, String>();
        titleMap.put("id", "11");
        titleMap.put("pid", "0");
        titleMap.put("content", "登录名");
        titleMap.put("fieldName", "u_login_id");
        titleMap.put("width", "20");
        Map<String, String> titleMap1 = new HashMap<String, String>();
        titleMap1.put("id", "1");
        titleMap1.put("pid", "0");
        titleMap1.put("content", "姓名");
        titleMap1.put("fieldName", "u_name");
        titleMap1.put("width", "20");
        Map<String, String> titleMap2 = new HashMap<String, String>();
        titleMap2.put("id", "2");
        titleMap2.put("pid", "0");
        titleMap2.put("content", "角色加部门");
        titleMap2.put("fieldName", null);
        titleMap2.put("width", "20");
        Map<String, String> titleMap3 = new HashMap<String, String>();
        titleMap3.put("id", "3");
        titleMap3.put("pid", "2");
        titleMap3.put("content", "角色");
        titleMap3.put("fieldName", "u_role");
        titleMap3.put("width", "15");
        Map<String, String> titleMap4 = new HashMap<String, String>();
        titleMap4.put("id", "4");
        titleMap4.put("pid", "2");
        titleMap4.put("content", "部门");
        titleMap4.put("fieldName", "u_dep");
        titleMap4.put("width", "15");
        Map<String, String> titleMap5 = new HashMap<String, String>();
        titleMap5.put("id", "22");
        titleMap5.put("pid", "0");
        titleMap5.put("content", "角色加部门1");
        titleMap5.put("fieldName", null);
        titleMap5.put("width", "20");
        Map<String, String> titleMap6 = new HashMap<String, String>();
        titleMap6.put("id", "22_1");
        titleMap6.put("pid", "22");
        titleMap6.put("content", "角色1");
        titleMap6.put("fieldName", "u_role");
        titleMap6.put("width", "10");
        Map<String, String> titleMap7 = new HashMap<String, String>();
        titleMap7.put("id", "22_2");
        titleMap7.put("pid", "22");
        titleMap7.put("content", "部门1");
        titleMap7.put("fieldName", "u_dep");
        titleMap7.put("width", "10");
        titleList.add(titleMap);
        titleList.add(titleMap1);
        titleList.add(titleMap2);
        titleList.add(titleMap3);
        titleList.add(titleMap4);
        titleList.add(titleMap5);
        titleList.add(titleMap6);
        titleList.add(titleMap7);
        // 单级的 行内数据
        List<Map<String, String>> rowList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Map<String, String> m = new HashMap<String, String>();
            if (i == 0) {
                m.put("u_login_id", "登录名zx1");
                m.put("u_name", "张三1");
            } else if (i > 0 && i < 3) {
                m.put("u_login_id", "登录名zx2");
                m.put("u_name", "张三2");
            } else if (i == 3) {
                m.put("u_login_id", "登录名zx1");
                m.put("u_name", "李四1");
            } else if (i > 3 && i < 7) {
                m.put("u_login_id", "登录名zx1");
                m.put("u_name", i == 6 ? "张三2" : "张三1");
            } else if (i > 6) {
                m.put("u_login_id", "登录名zx2");
                m.put("u_name", "李四1");
            }
            m.put("u_role", "角色" + i);
            m.put("u_dep", "部门" + i);
            m.put("u_type", "用户类型" + i);
            rowList.add(m);
        }
        ExcelPoiUtil excelTool = new ExcelPoiUtil("纵向合并单元格");
        Map<String, String> param = ImmutableMap.<String, String>builder().put("id", "id").put("pid", "pid")
                .put("content", "content").put("fieldName", "fieldName").put("width", "width").build();
        List<ColEntity> titleData = excelTool.colEntityTransformer(titleList, param, "0");
        //HSSFWorkbook workbook = excelTool.exportWorkbook(titleData, rowList,Arrays.asList(0,1));
        //excelTool.save(workbook,"C:\\Users\\Administrator\\Desktop\\纵向合并单元格.xlsx");
        heads.put("纵向合并单元格", titleData);// 每个sheet的表头，sheet名称为key
        datas.put("纵向合并单元格", rowList);// 每个sheet的内容，sheet名称为key
        types.put("纵向合并单元格", 0);// 每个sheet的样式类型，sheet名称为key
        mergeIndexs.put("纵向合并单元格", Arrays.asList(0, 1));// 每个sheet的默认行高，sheet名称为key
    }


    public static void 多级表头Obj2() throws Exception {
        List<TitleEntity> titleList = new ArrayList<>();
        titleList.add(new TitleEntity("title", null, "这里是title", null, 20));
        // 固定的五项表头
        titleList.add(new TitleEntity("项目", "title", "项目", null, 20));
        titleList.add(new TitleEntity("评分规则", "项目", "评分规则", null, 20));
        titleList.add(new TitleEntity("评分标准", "评分规则", "评分标准", null, 20));
        titleList.add(new TitleEntity("所在单位", "评分标准", "所在单位", "unit", 15));
        titleList.add(new TitleEntity("所在部门", "评分标准", "所在部门", "dept", 15));
        // 动态表头（实际项目需要根据数据库数据添加）
        int count = 0;
        for (int i = 0; i < 2; i++) {
            String xmId = "项目" + (i + 1);
            TitleEntity xm = new TitleEntity(xmId, "title", xmId, null, 20);
            titleList.add(xm);
            for (int j = 0; j < 2; j++) {
                String gzId = "项目" + (i + 1) + "-" + "规则" + (j + 1);
                String bzId = "项目" + (i + 1) + "-" + "标准" + (j + 1);
                TitleEntity gz = new TitleEntity(gzId, xmId, gzId, null, 20);
                TitleEntity bz = new TitleEntity(bzId, gzId, String.valueOf(j), null, 20);
                TitleEntity sl = new TitleEntity(bzId + "_sl" + j, bzId, "数量", "sl" + count, 10);
                TitleEntity df = new TitleEntity(bzId + "_df" + j, bzId, "得分", "df" + count, 10);
                titleList.add(gz);
                titleList.add(bz);
                titleList.add(sl);
                titleList.add(df);
                count++;
            }
        }
        // 填充数据
        List<Map<String, String>> rowList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Map<String, String> m = new HashMap<String, String>();
            if (i < 4) {
                m.put("unit", "A单位");
                m.put("dept", "部门" + i);
            } else {
                m.put("unit", "B单位");
                m.put("dept", "部门" + i);
            }
            for (int j = 0; j < count; j++) {
                m.put("sl" + j, String.valueOf(j));
                m.put("df" + j, String.valueOf(j + i));
            }
            rowList.add(m);
        }
        ExcelPoiUtil excelTool = new ExcelPoiUtil("实体类（entity）多级表头表格");
        Map<String, String> param = ImmutableMap.<String, String>builder().put("id", "id").put("pid", "pid")
                .put("content", "content").put("fieldName", "fieldName").put("width", "width").build();
        List<ColEntity> titleData = excelTool.colEntityTransformer(titleList, param, "title");
        //HSSFWorkbook workbook = excelTool.exportWorkbook(titleData, rowList,Arrays.asList(0));
        //excelTool.save(workbook,"C:\\Users\\Administrator\\Desktop\\多级表头Obj2.xlsx");
        heads.put("实体类（entity）多级表头表格2", titleData);// 每个sheet的表头，sheet名称为key
        datas.put("实体类（entity）多级表头表格2", rowList);// 每个sheet的内容，sheet名称为key
        types.put("实体类（entity）多级表头表格2", 0);// 每个sheet的样式类型，sheet名称为key
        mergeIndexs.put("实体类（entity）多级表头表格2", Arrays.asList(0));// 每个sheet的默认行高，sheet名称为key
    }


    public static void 多级表头Map() throws Exception {
        List<Map<String, String>> titleList = new ArrayList<>();
        Map<String, String> titleMap15 = new HashMap<>();
        titleMap15.put("id", "15");
        titleMap15.put("pid", "0");
        titleMap15.put("content", "班级数");
        titleMap15.put("fieldName", "collage");
        titleMap15.put("width", "20");
        Map<String, String> titleMap16 = new HashMap<>();
        titleMap16.put("id", "16");
        titleMap16.put("pid", "0");
        titleMap16.put("content", "学分");
        titleMap16.put("fieldName", "collage");
        titleMap16.put("width", "20");
        Map<String, String> titleMap17 = new HashMap<>();
        titleMap17.put("id", "17");
        titleMap17.put("pid", "0");
        titleMap17.put("content", "任课教师");
        titleMap17.put("fieldName", "collage");
        titleMap17.put("width", "20");
        Map<String, String> titleMap18 = new HashMap<>();
        titleMap18.put("id", "18");
        titleMap18.put("pid", "0");
        titleMap18.put("content", "合班情况");
        titleMap18.put("fieldName", "collage");
        titleMap18.put("width", "20");
        Map<String, String> titleMap19 = new HashMap<>();
        titleMap19.put("id", "19");
        titleMap19.put("pid", "0");
        titleMap19.put("content", "上课起止周次");
        titleMap19.put("fieldName", "collage");
        titleMap19.put("width", "20");


        Map<String, String> titleMap20 = new HashMap<>();
        titleMap20.put("id", "20");
        titleMap20.put("pid", "0");
        titleMap20.put("content", "合计总课时");
        titleMap20.put("fieldName", "collage");
        titleMap20.put("width", "20");


        Map<String, String> titleMap21 = new HashMap<>();
        titleMap21.put("id", "21");
        titleMap21.put("pid", "0");
        titleMap21.put("content", "备注");
        titleMap21.put("fieldName", "collage");
        titleMap21.put("width", "20");


        Map<String, String> titleMap22 = new HashMap<>();
        titleMap22.put("id", "22");
        titleMap22.put("pid", "0");
        titleMap22.put("content", "班级数");
        titleMap22.put("fieldName", "classNum");
        titleMap22.put("width", "20");

        Map<String, String> titleMap23 = new HashMap<>();
        titleMap23.put("id", "23");
        titleMap23.put("pid", "0");
        titleMap23.put("content", "班级数");
        titleMap23.put("fieldName", "credit");
        titleMap23.put("width", "20");


        Map<String, String> titleMap10 = new HashMap<>();
        titleMap10.put("id", "10");
        titleMap10.put("pid", "0");
        titleMap10.put("content", "序号");
        titleMap10.put("fieldName", "number");
        titleMap10.put("width", "20");
        Map<String, String> titleMap11 = new HashMap<>();
        titleMap11.put("id", "111");
        titleMap11.put("pid", "0");
        titleMap11.put("content", "二级学院");
        titleMap11.put("fieldName", "collage");
        titleMap11.put("width", "20");
        Map<String, String> titleMap12 = new HashMap<>();
        titleMap12.put("id", "12");
        titleMap12.put("pid", "0");
        titleMap12.put("content", "专业");
        titleMap12.put("fieldName", "major");
        titleMap12.put("width", "20");
        Map<String, String> titleMap13 = new HashMap<>();
        titleMap13.put("id", "13");
        titleMap13.put("pid", "0");
        titleMap13.put("content", "班级");
        titleMap13.put("fieldName", "class");
        titleMap13.put("width", "20");
        Map<String, String> titleMap14 = new HashMap<>();
        titleMap14.put("id", "14");
        titleMap14.put("pid", "0");
        titleMap14.put("content", "学生人数");
        titleMap14.put("fieldName", "studentNum");
        titleMap14.put("width", "20");
        Map<String, String> titleMap = new HashMap<>();
        titleMap.put("id", "11");
        titleMap.put("pid", "0");
        titleMap.put("content", "课程代码");
        titleMap.put("fieldName", "courseCode");
        titleMap.put("width", "20");
        Map<String, String> titleMap1 = new HashMap<>();
        titleMap1.put("id", "1");
        titleMap1.put("pid", "0");
        titleMap1.put("content", "课程名称");
        titleMap1.put("fieldName", "courseName");
        titleMap1.put("width", "20");
        Map<String, String> titleMap2 = new HashMap<>();
        titleMap2.put("id", "2");
        titleMap2.put("pid", "0");
        titleMap2.put("content", "计划课时");
        titleMap2.put("fieldName", null);
        titleMap2.put("width", "20");
        Map<String, String> titleMap8 = new HashMap<>();
        titleMap8.put("id", "5");
        titleMap8.put("pid", "2");
        titleMap8.put("content", "考核类型");
        titleMap8.put("fieldName", null);
        titleMap8.put("width", "20");
        Map<String, String> titleMap24 = new HashMap<>();
        titleMap24.put("id", "24");
        titleMap24.put("pid", "5");
        titleMap24.put("content", "考核方式");
        titleMap24.put("fieldName", "assessment");
        titleMap24.put("width", "20");
        Map<String, String> titleMap9 = new HashMap<>();
        titleMap9.put("id", "6");
        titleMap9.put("pid", "2");
        titleMap9.put("content", "周学时");
        titleMap9.put("fieldName", null);
        titleMap9.put("width", "20");
        Map<String, String> titleMap25 = new HashMap<>();
        titleMap25.put("id", "25");
        titleMap25.put("pid", "2");
        titleMap25.put("content", "理论实践分组");
        titleMap25.put("fieldName", null);
        titleMap25.put("width", "20");
        Map<String, String> titleMap26 = new HashMap<>();
        titleMap26.put("id", "26");
        titleMap26.put("pid", "25");
        titleMap26.put("content", "理论分组");
        titleMap26.put("fieldName", null);
        titleMap26.put("width", "20");
        Map<String, String> titleMap27 = new HashMap<>();
        titleMap27.put("id", "27");
        titleMap27.put("pid", "25");
        titleMap27.put("content", "实践分组");
        titleMap27.put("fieldName", null);
        titleMap27.put("width", "20");
        Map<String, String> titleMap3 = new HashMap<>();
        titleMap3.put("id", "3");
        titleMap3.put("pid", "2");
        titleMap3.put("content", "总课时");
        titleMap3.put("fieldName", "u_role");
        titleMap3.put("width", "15");
        Map<String, String> titleMap4 = new HashMap<>();
        titleMap4.put("id", "4");
        titleMap4.put("pid", "2");
        titleMap4.put("content", "总课时");
        titleMap4.put("fieldName", "u_dep");
        titleMap4.put("width", "15");
        Map<String, String> titleMap5 = new HashMap<>();
        titleMap5.put("id", "22");
        titleMap5.put("pid", "4");
        titleMap5.put("content", "理");
        titleMap5.put("fieldName", null);
        titleMap5.put("width", "20");
        Map<String, String> titleMap6 = new HashMap<>();
        titleMap6.put("id", "22_1");
        titleMap6.put("pid", "4");
        titleMap6.put("content", "实");
        titleMap6.put("fieldName", "u_role");
        titleMap6.put("width", "10");
        Map<String, String> titleMap7 = new HashMap<>();
        titleMap7.put("id", "22_2");
        titleMap7.put("pid", "4");
        titleMap7.put("content", "课外");
        titleMap7.put("fieldName", "u_dep");
        titleMap7.put("width", "10");

        titleList.add(titleMap10);
        titleList.add(titleMap11);
        titleList.add(titleMap12);
        titleList.add(titleMap13);
        titleList.add(titleMap14);
        titleList.add(titleMap);
        titleList.add(titleMap1);
        titleList.add(titleMap23);
        titleList.add(titleMap2);
        titleList.add(titleMap3);
        titleList.add(titleMap4);
        titleList.add(titleMap5);
        titleList.add(titleMap6);
        titleList.add(titleMap7);
        titleList.add(titleMap8);
        titleList.add(titleMap24);
        titleList.add(titleMap9);
        titleList.add(titleMap25);
        titleList.add(titleMap26);
        titleList.add(titleMap27);
        titleList.add(titleMap17);
        titleList.add(titleMap18);
        titleList.add(titleMap19);
        titleList.add(titleMap20);
        titleList.add(titleMap21);
        // 单级的 行内数据
        List<Map<String, String>> rowList = new ArrayList<>();
//        for (int i = 0; i < 7; i++) {
//            Map<String, String> m = new HashMap<String, String>();
//            m.put("u_login_id", "登录名zx" + i);
//            m.put("u_name", "张三" + i);
//            m.put("u_role", "角色" + i);
//            m.put("u_dep", "部门" + i);
//            m.put("u_type", "用户类型" + i);
//            rowList.add(m);
//        }
        ExcelPoiUtil excelTool = new ExcelPoiUtil("List<Map>多级表头");
        Map<String, String> param = ImmutableMap.<String, String>builder().put("id", "id").put("pid", "pid")
                .put("content", "content").put("fieldName", "fieldName").put("width", "width").build();
        List<ColEntity> titleData = excelTool.colEntityTransformer(titleList, param, "0");
        heads.put("教学班数据导出", titleData);// 每个sheet的表头，sheet名称为key
        datas.put("教学班数据导出", rowList);// 每个sheet的内容，sheet名称为key
        types.put("教学班数据导出", 0);// 每个sheet的样式类型，sheet名称为key
    }


    @ApiOperation("测试动态设置表头导出")
    @GetMapping(value = "/test3")
    public void test3(HttpServletResponse response) throws Exception {


//        List<Teacher> teacherList = teacherService.lambdaQuery().eq(Teacher::getTaskId, 1000053).eq(Teacher::getBaseCollegeId, "1809820209408442370").list();
//        List<String> filePath = new ArrayList<>();
//        teacherList.forEach(o -> {
//            String s = scheduleService.teacherScheduleToExcel(1000053, o.getTeacherId(), null);
//            filePath.add(s);
//        });
//
//
//        try {
//
//            String storePath = "/教师课表导出-" + System.currentTimeMillis() + ".zip";
////        String storePath = "/" + "A" + UUID.randomUUID().toString() + "/" + "A" + LocalDate.now() + ".xlsx";
//            String targetPath = GlobalConstant.OUTPUT_EXCEL_PATH + storePath;
//
//            FileUtil.del(targetPath);
//
//            FileOutputStream fos = new FileOutputStream(targetPath);
//            ZipOutputStream zos = new ZipOutputStream(fos);
//
//            for (String url : filePath) {
//                String[] parts = url.split("/");
//                String lastPart = parts[parts.length - 1];
//                String secondLastPart = parts[parts.length - 2];
//                String urls = "http://localhost:18888/ccas//"+"static/OutputExcel/"+ URLEncoder.encode(secondLastPart,"utf-8")+"/"+URLEncoder.encode(lastPart,"utf-8");
//
//                URL fileUrl = new URL(urls);
//                String fileName = url.substring(url.lastIndexOf("/") + 1);
//
//                InputStream is = fileUrl.openStream();
//                zos.putNextEntry(new ZipEntry(fileName));
//
//                byte[] buffer = new byte[1024];
//                int bytesRead;
//                while ((bytesRead = is.read(buffer)) != -1) {
//                    zos.write(buffer, 0, bytesRead);
//                }
//
//                is.close();
//                zos.closeEntry();
//            }
//
//            zos.close();
//            fos.close();
//
//            System.out.println("所有文件已成功打包到output.zip");


//        } catch (IOException e) {
//            e.printStackTrace();
//        }


        List<Student> student = studentService.lambdaQuery().eq(Student::getTaskId, 1000053).list();

        ArrayList<String> baseStudentIds = new ArrayList<>();


        baseStudentIds.add("202203150138");
        baseStudentIds.add("202203150204");
        baseStudentIds.add("202203150342");
        baseStudentIds.add("202203610126");
        baseStudentIds.add("202203610128");
        baseStudentIds.add("202203610129");
        baseStudentIds.add("202203610141");
        baseStudentIds.add("202203610142");
        baseStudentIds.add("202203610143");
        baseStudentIds.add("202203610144");
        baseStudentIds.add("202203610145");
        baseStudentIds.add("202203610414");
        baseStudentIds.add("202203610519");
        baseStudentIds.add("202203610638");
        baseStudentIds.add("202203610717");
        baseStudentIds.add("202203170219");
        baseStudentIds.add("202203220205");
        baseStudentIds.add("202203220208");
        baseStudentIds.add("202203220406");
        baseStudentIds.add("202203220439");
        baseStudentIds.add("202203220545");
        baseStudentIds.add("202203220627");
        baseStudentIds.add("202203220641");
        baseStudentIds.add("202203540120");
        baseStudentIds.add("202203540121");
        baseStudentIds.add("202203540204");
        baseStudentIds.add("202203540226");
        baseStudentIds.add("202203540233");
        baseStudentIds.add("202203540239");
        baseStudentIds.add("202203540240");


        List<Student> collect = student.stream().filter(p -> baseStudentIds.contains(p.getBaseStudentId())).collect(Collectors.toList());

        List<TeachingClassStudent> teachingClassStudents = new ArrayList<>();


        collect.forEach(o -> {
            TeachingClassStudent teachingClassStudent = new TeachingClassStudent();
            teachingClassStudent.setTeachingClassId(2167L);
            teachingClassStudent.setFlag(1);
            teachingClassStudent.setStudentId(o.getStudentId());
            teachingClassStudent.setCourseId(2005239L);
            teachingClassStudents.add(teachingClassStudent);

        });
        teachingClassStudentService.saveOrUpdateBatch(teachingClassStudents);

//        List<File> fileList = new ArrayList<>();
//        for (String s : filePath) {
//            File file = new File(s);
//            fileList.add(file);
//        }
//        response.setHeader("content-type", "application/octet-stream");
//        response.setContentType("application/octet-stream");
//        response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=configDetail.zip");
//        try {
//            ZipUtils.downloadZipForFiles(response.getOutputStream(), fileList);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


    }


}
